/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.BankAccountBean;
import com.minierp.model.BankAccount;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class BankAccountValidator implements Validator {
	public boolean supports(Class clazz) {
		return BankAccountBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		BankAccountBean bean = (BankAccountBean) obj;
		BankAccount form = bean.getBankAccount();
		if (form.getAccountName() != null
				&& !form.getAccountName().trim().equals("")) {
			if (form.getBankName() != null
					&& !form.getBankName().trim().equals("")) {
				if (form.getTallySetId() == 0L) {
					errors.rejectValue("bankAccount.tallySetId", "", "请选择『帐套』");
				}
			} else {
				errors.rejectValue("bankAccount.bankName", "", "请输入『银行名称』");
			}
		} else {
			errors.rejectValue("bankAccount.accountName", "", "请输入『开户名称』");
		}

	}
}